<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="tag" uri="surveyonline-taglib" %>

<%@ page import="fr.univ.surveyonline.model.Survey" %>
<%@ page import="fr.univ.surveyonline.model.Contraintes" %>
<%@ page import="fr.univ.surveyonline.model.PropertiesNumber" %>
<%@ page import="fr.univ.surveyonline.model.allEnum.*" %>
<%@ page import="fr.univ.surveyonline.model.Survey" %>
<%@ page import="fr.univ.surveyonline.model.ResponseManager" %>
<%@ page import="fr.univ.surveyonline.datastore.PMF" %>
<%@ page import="java.util.*" %>
<%@ page import="fr.univ.surveyonline.language.Language" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">


<%@page import="fr.univ.surveyonline.model.DateHelpers"%><html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fr" lang="fr">
<head>
    <title><tag:languageTag id="title"/></title>
	<%@ include file="/layout/head.tag" %>
</head>
<body>

<div id="global">
	<div id="entete">
		<%@ include file="/layout/menu.tag" %>
	</div>
	<div id="contenu">
		<h2><tag:languageTag id="contrainte-choice_title"/></h2>
		<%
		String langue = "FR";
		for (Cookie c : request.getCookies()) {
			if (c.getName().equals("langue")) {
				langue = c.getValue(); 
				break;
			}
		}
		
		User u = null;
		if (request.getSession().getAttribute("user") == null) {
			String message = (String)Language.getWord("contrainte_be_connected",langue);
			request.setAttribute("message", message);
			RequestDispatcher rd = request.getRequestDispatcher("unaccessible.jsp");
			try {
				rd.forward(request, response);
			} catch (ServletException e) {
				e.printStackTrace();
			}			
		} else {
			u = (User) request.getSession().getAttribute("user");
		}
		
		List<Survey> s = (List<Survey>) PMF.getAllFromClass(Survey.class);
		if(s==null) {
			System.out.println("null");
		}
		//liste
		List<Survey> userSurveys  = new ArrayList<Survey>();
		for (Survey s2 : s) {
			if ((s2.getSondeurKey().getId() == u.getKey().getId()) 
					&& (!s2.isConstraintsVerified())
					&& (!s2.isInLine())) {
				userSurveys.add(s2);
			}
		}
		
		if (userSurveys.size() == 0) {
			String message = (String)Language.getWord("contrainte-choice_check",langue);
			out.print("<p>"+message+"</p>");
		} else {
			out.print("<ul>");
			for (Survey s3 : userSurveys) {
				out.print("<li><a href=/contraintes.jsp?survey="+ s3.getKey().getId()+">"+ s3.getName()+"</a></li>");
			}
			out.print("</ul>");
		}
		%>
		<div class="clear"></div>
	</div>
	<div id="pied">
		<%@ include file="/layout/pied.tag" %>
	</div>
</div>

</body>
</html>